package com.surfacing.rcp.client.modelManager;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Display;

import com.surfacing.rcp.model.entity.StatTransportziel;

/**
 * This class manages the staff members
 * 
 * @author Michael
 */
public class StatTransportzielManager extends PropertyManager {
	// the item list
	private List<StatTransportziel> objectList = new ArrayList<StatTransportziel>();

	/**
	 * Adds a new stats to the list
	 * 
	 * @param stats
	 *            the staff member to add
	 */
	public void add(final StatTransportziel stats) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				objectList.add(stats);
				firePropertyChange("STATS_TPZ_ADD", null, stats);
			}
		});
	}

	/**
	 * Removes the staff member from the list
	 * 
	 * @param stats
	 *            the member to remove
	 */
	public void remove(final StatTransportziel stats) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				objectList.remove(stats);
				firePropertyChange("STATS_TPZ_REMOVE", stats, null);
			}
		});
	}

	/**
	 * Updates the staff member in the list
	 * 
	 * @param stats
	 *            the member to update
	 */
	public void update(final StatTransportziel stats) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				// assert we have this staff member
				if (!objectList.contains(stats))
					return;
				// get the position of the entry
				int id = objectList.indexOf(stats);
				objectList.set(id, stats);
				firePropertyChange("STATS_TPZ_UPDATE", null, stats);
			}
		});
	}

	/**
	 * Removes all elements and resets the list
	 */
	public void removeAllElements() {
		objectList.clear();
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				firePropertyChange("STATS_TPZ_CLEARED", null, null);
			}
		});
	}

	/**
	 * Converts the list to an array
	 * 
	 * @return the list as a array
	 */
	public Object[] toArray() {
		return objectList.toArray();
	}

	/**
	 * Returns a list with all staff members
	 * 
	 * @return a staff list
	 */
	public List<StatTransportziel> getStatsList() {
		return objectList;
	}
}
